package com.example.day20;

/**
 * @author Lenovo
 */
public class Box {
    private int milk;
    private boolean state = false;
    public synchronized void put(int milk){
        if(state){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.milk = milk;
        state = true;
        System.out.println("生产者生产了"+milk+"ml牛奶");
        notifyAll();
    }
    public synchronized void get(){
        if(!state){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("消费者消费了"+milk+"ml牛奶");
        state = false;
        notifyAll();
    }
    }

